﻿using System;

namespace Layers.History
{
    public class DataNode
    {
        protected BitBuffer _buffer;

        public BitBuffer Buffer { get { return _buffer; } }

        public Type Type { get; set; }
        public int Count { get; set; }

        public DataNode()
        {
            Type = null;
            _buffer = new BitBuffer(128);
            Count = 0;
        }

        public virtual IStream GetStream()
        {
            return null;
        }
    }

    public class HuffmanNode : DataNode
    {
        public object First { get; set; }
        public object Tick { get; set; }
    }

    public class DiffHuffmanNode : HuffmanNode
    {
        protected DataNodeStream<int> GetCodeStream()
        {
            return new HuffmanNodeStream(
                   this,
                   new BitStream(_buffer)
                   );
        }

        public override IStream GetStream()
        {
            switch (Type.GetTypeCode(Type))
            {
                case TypeCode.Double:
                    return new DiffNodeStream_Double(GetCodeStream());

                case TypeCode.Int16:case TypeCode.Int32:case TypeCode.Int64:
                    return new DiffNodeStream_Int(GetCodeStream());
            }
            throw new InvalidOperationException();
        }

    }



}